#include "mvc/model/configuration.h"

/**
  * The configuration constructor.
  * @param id - the id of the configuration
  * @param parameters - the parameters needed to create the geometry
  */
Configuration::Configuration(int id, Parameters *parameters)
{
    _id = id;
    _parameters = parameters;
}

/**
  *
  */
Configuration::~Configuration()
{
    if(!_parameters)
        delete _parameters;

    free_geometry_memory();
    free_refcurves_memory();
}

/**
  * release the memory used to keep the simulation points.
  */
void Configuration::clear()
{
    free_steps_memory();
}

/**
  * release the memory used to keep the geometry points.
  */
void Configuration::free_geometry_memory()
{
    for(int i = 0; i < _geometries.size(); i++)
        delete _geometries.at(i);
}

/**
  * release the memory used to keep the reference curves points.
  */
void Configuration::free_refcurves_memory()
{
    cout << "Configuration::free_refcurves_memory" << endl;
}

/**
  * release the memory used to keep the simulation points.
  */
void Configuration::free_steps_memory()
{
    for(int i = 0; i < _zones.size(); i++)
    {
        time_zone *ctzone = _zones.at(i);
        QVector<Zone> &czones = ctzone->zones;
        for(int j = 0; j < czones.size(); j++)
        {
            Zone czone = czones.at(j);
            for(int k = 0; k < czone.size(); k++)
                delete czone.at(k);
        }

        delete _zones.at(i);
    }
}
